package com.umiwe.permission.service.impl;

import com.umiwe.entity.UmiwePermission;
import com.umiwe.permission.mapper.PermissionMapper;
import com.umiwe.permission.mapper.RolePermissionMapper;
import com.umiwe.permission.service.PermissionService;
import com.umiwe.utils.Result;
import com.umiwe.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    @Override
    public Result filterStatus(String url) {
        if(permissionMapper.filterStatus(url) != null){
            // 不过滤
           return Result.success(true);
        }else{
            // 过滤
           return Result.success(false);
        }
    }

    /**
     * 查询所有的权限信息
     * @return
     */
    @Override
    public Result permissionList() {
        return Result.success(permissionMapper.selectList(null));
    }

    /**
     * 基于权限id修改权限信息
     * @param umiwePermission
     * @return
     */
    @Override
    public Result permissionUpdate(UmiwePermission umiwePermission) {
        return Result.success(permissionMapper.updateById(umiwePermission));
    }

    /**
     * 基于权限id新增信息
     * @param umiwePermission
     * @return
     */
    @Override
    public Result permissionInsert(UmiwePermission umiwePermission) {
        return  Result.success(permissionMapper.insert(umiwePermission));
    }

    /**
     * 基于权限id删除信息
     * @param umiwePermission
     * @return
     */
    @Override
    public Result permissionDelete(UmiwePermission umiwePermission) {
        if(umiwePermission.getId()==null)
            throw  new IllegalArgumentException("没有此角色");
        rolePermissionMapper.deletePerRole("permission_id",umiwePermission.getId());
        int rows = permissionMapper.deleteById(umiwePermission);
        return Result.success(rows);
    }
}
